<?php

namespace App\Http\Controllers\web;

use App\Http\Controllers\Controller;
use App\Repository\RepositoryInterface\DistributionInterface;
use Illuminate\Http\Request;
//分销类
class DistributionController extends Controller
{
    protected $dis;

    public function __construct(DistributionInterface $dis){
        $this->dis = $dis;
    }

    /**
     * @param Request $request
     * @return array  修改会员会员
     */
    public function memberSet(Request $request)
    {
        try {
            $data = $request->all();
            $id = $request->get('id',1);
            $data = $this->dis->memberSet($id,$data);
            return ['code'=>20000,'msg'=>'success','data'=>[]];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }

    /**
     * @param Request $request
     * @return array 获取设置
     */
    public function getSet(Request $request)
    {
        try {
            $id = $request->post('id',1);
            $data = $this->dis->getSet($id);
            return ['code'=>20000,'msg'=>'success','data'=>$data];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }
    /**
     * @param Request $request
     * @return array 获取设置
     */
    public function distributionUpdate(Request $request)
    {
        try {
            $data = $request->all();
            $data = $this->dis->distributionUpdate($data);
            return ['code'=>20000,'msg'=>'success','data'=>[]];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }
    /**
     * @param Request $request
     * @return array 获取设置
     */
    public function distributionAdd(Request $request)
    {
        try {
            $data = $request->all();
            $data = [
                'name'=>$data['name'],
                "one" => $data['one'],
                "two" => $data['two'],
                "three" => $data['three'],
                "avatar" => $data['cover']
            ];
            $data = $this->dis->distributionAdd($data);
            return ['code'=>20000,'msg'=>'success','data'=>[]];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }
    /**
     * @param Request $request
     * @return array 运营商列表
     */
    public function enterList(Request $request)
    {
        try {
            $page = $request->get('page');
            $data = $this->dis->enterList($page);
            return ['code'=>20000,'msg'=>'success','data'=>$data];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }
    /**
     * @param Request $request
     * @return array 删除
     */
    public function distributionDel(Request $request)
    {
        try {
            $id = $request->get('id');
            $data = $this->dis->distributionDel($id);
            return ['code'=>20000,'msg'=>'success','data'=>$data];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }

    /**
     * @param Request $request
     * @return array  获取单条数据
     */
    public function getDistribution(Request $request)
    {
        try {
            $id = $request->get('id');
            $data = $this->dis->getDistribution($id);
            return ['code'=>20000,'msg'=>'success','data'=>$data];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }
    /**
     * @param Request $request
     * @return array  获取佣金
     */
    public function getRecord(Request $request)
    {
        try {
            $page = $request->get('page');
            $data = $this->dis->getRecord($page);
            return ['code'=>20000,'msg'=>'success','data'=>$data];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }

    /**
     * @param Request $request
     * @return array 搜索
     */
    public function recordSearch(Request $request)
    {
        try {
            $name =  $request->get('name');
            $data = $this->dis->recordSearch($name);
            return ['code'=>20000,'msg'=>'success','data'=>$data];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }

    /**
     * @param Request $request
     * @return array 统计营业额
     */
    public function statistics(Request $request)
    {
        try {
            $data = $this->dis->statistics();
            return ['code'=>20000,'msg'=>'success','data'=>$data];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }

    /**
     * @param Request $request
     * @return array 统计线下
     */
    public function offline(Request $request)
    {
        try {
            $data = $this->dis->offline();
            return ['code'=>20000,'msg'=>'success','data'=>$data];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }

    /**
     * @param Request $request
     * @return array 统计余额
     */
    public function balance(Request $request)
    {
        try {
            $data = $this->dis->balance();
            return ['code'=>20000,'msg'=>'success','data'=>$data];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }
    /**
     * @param Request $request
     * @return array 商品支付统计
     */
    public function goodsPay(Request $request)
    {
        try {
            $data = $this->dis->goodsPay();
            return ['code'=>20000,'msg'=>'success','data'=>$data];
        }catch (\Exception $exception){
            return ['code'=>5000,'msg'=>$exception,'data'=>[]];
        }
    }
}
